package com.www.applyword.ui.home;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.HomeAdapter4;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.SettlementBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2019/12/13 0013 16:21
 * version: 1.0
 * @author Administrator
 */
public class SettlementActivity extends BaseActivity {
    @BindView(R.id.rl)
    RecyclerView rlJob;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refresh;
    private HomeAdapter4 mHotJobAdapter;

    private int page = 1;
    private int Rows = 10;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.settlement_activity);
        setTitle("结算");
        initDate();
    }

    private void initDate() {
        rlJob.setLayoutManager(new LinearLayoutManager(this));
        rlJob.setItemAnimator(new DefaultItemAnimator());
        mHotJobAdapter = new HomeAdapter4(this);
        rlJob.setAdapter(mHotJobAdapter);

        refresh.setOnRefreshListener(refreshLayout -> getOrderList(true));

        refresh.setOnLoadMoreListener(refreshLayout -> getOrderList(false));

        getOrderList(true);

    }

    @Override
    protected void loadData() {

    }


    private void getOrderList(boolean isRefresh) {
        if (isRefresh) page = 1;
        Map<String, Object> params = new HashMap<>();
        params.put("OrderID", getIntent().getStringExtra("OrderID"));
        params.put("Page", page + "");
        params.put("Rows", Rows + "");
        HttpClient.get(SettlementActivity.this, Constants.GETORDERITEMS, params, new CallBack<List<SettlementBean>>() {
            @Override
            public void onSuccess(List<SettlementBean> orderBeans) {
                if (isRefresh) {
                    refresh.finishRefresh(true);
                    if (orderBeans.size() == 0) {
                        showEmpty(true, vsEmpty, 0);
                    } else {
                        showEmpty(false, vsEmpty, 0);
                    }
                    mHotJobAdapter.replaceAll(orderBeans, true);
                } else {
                    if (orderBeans.size() > 0) {
                        refresh.finishLoadMore(true);
                        mHotJobAdapter.addAll(orderBeans);
                    } else {
                        refresh.finishLoadMoreWithNoMoreData();
                    }
                }
                page++;
            }
        });
    }
}
